package com.example.student.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.example.student.utils.UserUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("createBy", UserUtils.getName(),metaObject);
        this.setFieldValByName("deleteFlag", 0,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("updateBy", UserUtils.getName(),metaObject);
    }
}
